package com.leyou.search.listener;

import com.leyou.search.service.IndexService;
import com.leyou.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ItemListener {
    @Resource
    private IndexService indexService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.up.queue",durable = "true"),
            exchange = @Exchange(name = "jhj",type = ExchangeTypes.TOPIC),
            key = "up"
    ))
    public void listenUp(Long spuId){
        if (spuId!=null)
            indexService.saveGoodsById(spuId);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.down.queue",durable = "true"),
            exchange = @Exchange(name = "jhj",type = ExchangeTypes.TOPIC),
            key = "down"
    ))
    public void listenDown(Long spuId){
        if (spuId!=null)
            indexService.deleteGoodsById(spuId);
    }
}
